<?php

	/*
	*	修改Model
	*/
	
	
	class ModifyModel {
		
		private $tableKeyList;
		
		private $tableValueList;
		
		public function __construct($_post, $_files) {
			
			$this->tableKeyList = array (
			
				'name',
				'gender',
				'birthday',
				'email','tell',
				'school',
				'major',
				'hobby',
				'has_annex',
				'statu'
				
			);
			
		}
		
		
		//	构建sql语句
		public function sqlBuild() {
			
			$_POST['has_annex'] = 0;
			
			if(!empty($_FILES['resume_annex']['name'])) {
				
				$_POST['has_annex'] = 1;
				
			}
			
			$_POST['birthday'] = $_POST['birthYear'] . '-' . $_POST['birthDay'];
			
			$_POST['email'] = $_POST['personMail'];
			
			$_POST['statu'] = 1;
			
			foreach($this->tableKeyList as $k => $v) {
				
				$this->tableValueList[$v] = $_POST[$v];
				
			}
			
		}
		
		
		//	更新
		public function update($_post, $id) {
			
			$this->sqlBuild();
			
			$tableModel = new DataTableModel();
			
			if($tableModel->modify($this->tableKeyList, $this->tableValueList, $id)) {
				
				return true;
				
			}
			
			return false;
			
		}
		
		
		//	检查提交到服务器的信息
		public function checkInfo() {
			
			$ck_handle = new Check();
			
			if(!$ck_handle->checkName()) {
				
				return 2;
				
			}
			
			if(!$ck_handle->checkMail()) {
				
				return 3;
				
			}
			
			
			if(!$ck_handle->checkTell()) {
				
				return 4;
				
			}
	
			if(!$ck_handle->checkSchool()) {
				
				return 5;
				
			}
			
			if(!empty($_FILES['resume_annex']['name'])) {
				
				$this->has_annex = 1;
				
				$ck_handle->checkFile($_FILES['resume_annex']['name']);
			}
			
			return true;
		}
	}
	
?>